using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Gencode.PrsUtil.Controls;

namespace Personalplaner.Modules.Dienstplan.Print
{
	public partial class GridPrintPreview : Form
	{
		Personalplaner.Modules.Dienstplan.Print.IGridPrintDocument gridDocument;
		public Personalplaner.Modules.Dienstplan.Print.IGridPrintDocument GridDocument
		{
			get
			{
				return gridDocument;
			}
			set
			{
				gridDocument = value;
			}
		}

		List<PrinteableGrid> printeableGrids;
		public List<PrinteableGrid> PrinteableGrids
		{
			get
			{
				return printeableGrids;
			}
			set
			{
				printeableGrids = value;
			}
		}

		//int pageSize;
		int currentGridIndex = 0;
		public int GridIndex
		{
			get
			{
				return currentGridIndex;
			}
			set
			{
				currentGridIndex = value;
			}
		}


		public DataGridView Grid
		{
			get
			{
				return printeableGrids[currentGridIndex].Grid;
			}
		}

		public List<DataGridView> Grids
		{
			get
			{
				List<DataGridView> tmp = new List<DataGridView>();
				for (int i = 0; i < printeableGrids.Count; i++)
				{
					tmp.Add(printeableGrids[i].Grid);
				}
				return tmp;
			}
		}

		bool closeAfterCreate = true;
		/// <summary>
		/// Close the Dialog automaticaly after the grids are created.
		/// </summary>
		public bool CloseAfterCreate
		{
			get
			{
				return closeAfterCreate;
			}
			set
			{
				closeAfterCreate = value;
			}
		}




		public GridPrintPreview()
		{
			InitializeComponent();

			printeableGrids = new List<PrinteableGrid>();
		}

		public void PrepareGridDerfaults()
		{
			foreach (PrinteableGrid grid in printeableGrids)
			{
				//Set new Fontsize
				grid.Grid.Font = new Font("Microsoft Sans Serif", 7);
			}
		}

		private void PrintGridPrep_Load(object sender, EventArgs e)
		{
			GridDocument.CreateGridsForPrint();

			PrepareGridDerfaults();
			DrawGrids();

			GridDocument.RenderGrid();

			if (closeAfterCreate)
				this.Close();
		}

		public void DrawGrids()
		{
			foreach (PrinteableGrid grid in printeableGrids)
			{
				TabPage page = new TabPage("");
				grid.Dock = DockStyle.Fill;
				page.Controls.Add(grid);
				gridPage.TabPages.Add(page);
				gridPage.SelectedIndex = gridPage.TabPages.Count - 1;
			}
		}
	}
}